﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LastFeed.cs" company="">
//   
// </copyright>
// <summary>
//   The last feed.
// </summary>
// --------------------------------------------------------------------------------------------------------------------


using System;

namespace Systemathics.FrameWork
{
    public sealed class LastFeed
    {
        public Trade Trade              { get; set; }
        public Blotter Blotter          { get; set; }
        public MarketData Marketdata    { get; set; }

        public bool TradeCheck          { get; private set; }
        public bool BlotterCheck        { get; private set; }
        public bool MarketdataCheck     { get; private set; }

        public LastFeed(Guid Guid)
        {
            Trade = new Trade(Guid);
            Blotter = new Blotter(Guid);
            Marketdata = new MarketData(Guid);
            TradeCheck = false;
            BlotterCheck = false;
            MarketdataCheck = false;
        } 

        public void CheckTrade()
        {
            lock (Trade)
            {
                if (Trade.Price * Trade.Size != 0)
                    TradeCheck = true;
            }
        }
        public void CheckMarketData()
        {
            lock (Marketdata)
            {
                if (Marketdata.Open * Marketdata.High * Marketdata.Low * Marketdata.Close != 0)
                    MarketdataCheck = true;
            }
        }
        public void  CheckBlotter(QuoteLevel ql)
        {
            lock (Blotter)
            {
                try
                {
                    if (Blotter[ql].BidSize * Blotter[ql].Bid * Blotter[ql].Ask * Blotter[ql].AskSize != 0)
                        BlotterCheck = true;
                }
                catch (OverflowException)
                {
                    BlotterCheck = false;
                }
            }
        }
    }
}